using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace HitEditor
{
    using XNAFight;
    using SysWinForms = System.Windows.Forms; // Pour eviter les conflits de namespace

    public class HitEditorGame : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        MainWindow main_window;

        public HitEditorGame()
        {
            graphics = new GraphicsDeviceManager(this) { PreferredBackBufferWidth = 500, PreferredBackBufferHeight = 400 };
            graphics.GraphicsProfile = GraphicsProfile.Reach;
            Content.RootDirectory = "XNAFightContent";
            CommonContent.CurrentGame = this;
        }

        protected override void Initialize()
        {
            base.Initialize();

            SysWinForms.Form gameWindowForm = (SysWinForms.Form)SysWinForms.Form.FromHandle(this.Window.Handle);
            gameWindowForm.Shown += new EventHandler(gameWindowForm_Shown);

            this.main_window = new MainWindow();
            main_window.HandleDestroyed += new EventHandler(myForm_HandleDestroyed);
            main_window.Show();

            main_window.setXnaPanelDimensions(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
        }
        void myForm_HandleDestroyed(object sender, EventArgs e)
        {
            this.Exit();
        }

        void gameWindowForm_Shown(object sender, EventArgs e)
        {
            ((SysWinForms.Form)sender).Hide();
        }

        protected override void LoadContent()
        {
            CommonContent.SpriteBatch = new SpriteBatch(GraphicsDevice);
            CommonContent.DefaultFont = this.Content.Load<SpriteFont>("DefaultFont");
            CommonContent.SmallFont = this.Content.Load<SpriteFont>("SmallFont");

            // Par exemple si on veut ajouter le hit editor dans le panneau XNA on peut faire :
            Components.Add(new HitEditor());
        }

        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);

            base.Draw(gameTime);

            this.GraphicsDevice.Present(null, null, this.main_window.XnaPanelHandle);
        }
    }
}
